#ifndef DIRTREE_H
#define DIRTREE_H

#include <QTreeWidget>

namespace Jcr
{
class DirTreePrivate;
class DirTree : public QTreeWidget
{
    Q_OBJECT
public:
    enum ItemType { Root, Brand, Model };
    explicit DirTree(QWidget *parent = 0);
    ~DirTree();

    QString currentDir() const;

public slots:
    bool reload();
    bool find(const QString& keyword);

    void setRoot(const QString& root);
    QString root() const;

    void renameCurrentDir();
    void deleteCurrentDir();
    void locateCurrentDir();
    void createDir(const QString& name);

signals:
    void load(const QString& folder);
    void download(const QUrl& url);
    void notify(const QString& msg);
    void modelChanged(const QString& model);

protected:
    void contextMenuEvent(QContextMenuEvent *e);
    void keyPressEvent(QKeyEvent* e);

private slots:
    void onItemDblClicked(QTreeWidgetItem* item, int column);
    void onItemClicked(QTreeWidgetItem* item, int column);

    void locate();
    void addBrand();
    void renameBrand();
    void deleteBrand();
    void addModel();
    void renameModel();
    void deleteModel();
    void monitorClipboardDataChanged();
    void copyTextToClipboard();
    void copyDataToClipboard();

private:
    void traverseDir(QTreeWidgetItem* parentItem, const QString& dirPath, ItemType it);

private:
    DirTreePrivate* d_ptr;
    friend class DirTreePrivate;
    Q_DISABLE_COPY(DirTree)
};

} // namespace jcr
#endif // DIRTREE_H
